package com.wujilee.shardingsphere.service.impl;

import com.wujilee.shardingsphere.entity.EntityUser;
import com.wujilee.shardingsphere.mapper.EntityUserMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author liwuji
 * @date 2024/5/20
 * @desc
 **/
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private EntityUserMapper userMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveUser(EntityUser entityUser) {
        if (entityUser.getId() != null) {
            userMapper.insert(entityUser);
            return;
        }
        userMapper.updateById(entityUser);
        EntityUser entityUser1 = userMapper.selectById(entityUser.getId());
        System.out.println(entityUser1.getId());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void batchSaveUser(List<EntityUser> entityUsers) {
        userMapper.batchInsertUser(entityUsers);
    }

    @Override
    public EntityUser getUserById(Long id) {
        return userMapper.selectById(id);
    }
}
